<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

  <%@ include file="dengluPublic.jsp" %>
    <%@ include file="daohangPublic.jsp"%>
    <br /><br /><br />    
     <%!
     String ino;
     String fname;
	 String fno;  
	 String id;  
      %>    
    <%
    request.setCharacterEncoding("utf-8");
    fno=request.getParameter("cno"); 
    id=request.getParameter("id"); 
    System.out.println("??????"+fno); 
     %>
          
     
     <% 
		String driverClass="com.mysql.jdbc.Driver";
	    String url="jdbc:mysql://localhost:3306/vote?useSSL=false";
	    String user="root";
	    String password="womenilu2580";
	    Class.forName(driverClass);
	    Connection conn=DriverManager.getConnection(url,user,password);
	    Statement stat=conn.createStatement();	 
	    String sql="select * from t_customer where cname='"+customer.getCname()+"'";
	    ResultSet rs=stat.executeQuery(sql);
	    while(rs.next()){
	    ino=rs.getString("cno");  	        	
	    }
	    %>	    
	    
	    <% 
		String driverClass1="com.mysql.jdbc.Driver";
	    String url1="jdbc:mysql://localhost:3306/vote?useSSL=false";
	    String user1="root";
	    String password1="womenilu2580";
	    Class.forName(driverClass1);
	    Connection conn1=DriverManager.getConnection(url1,user1,password1);
	    Statement stat1=conn1.createStatement();	 
	    String sql1="select * from t_customer where cno="+fno+"";
	    ResultSet rs1=stat1.executeQuery(sql1);
	    while(rs1.next()){
	    fname=rs1.getString("cname");  	        	
	    }
	    %>	    
	    <%
	    if(customer.getCname().equals(fname))
	    {
	  
	    %>
	   
	    <% 
	    }else{
	     %>
	    <% 
	    Class.forName(driverClass1);
	    Connection conn2=DriverManager.getConnection(url1,user1,password1);
	    Statement stat2=conn2.createStatement();	 
	    String sql2="insert into friend values('"+customer.getCname()+"','"+fname+"',"+ino+","+fno+")";
	    stat2.executeUpdate(sql2);
	    Class.forName(driverClass1);
	    Connection conn3=DriverManager.getConnection(url1,user1,password1);
	    Statement stat3=conn3.createStatement();	 
	    String sql3="insert into friend values('"+fname+"','"+customer.getCname()+"',"+fno+","+ino+")";
	    stat3.executeUpdate(sql3);
	    }	    	    
	    %>
	    <%
	    
	     %>
	    
<%
response.sendRedirect("sciencechat.jsp");
 %>
	    	 		 